import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import 'package:xiaotiancai/page/DetailPage.dart';
import 'package:xiaotiancai/style.dart';
import 'package:xiaotiancai/widget/luckdraw/LuckyDraw.dart';
import 'package:xiaotiancai/widget/luckdraw/LuckyBean.dart';
class HomePage extends StatefulWidget{
  const HomePage({super.key});
  @override
  State<StatefulWidget> createState()=>_HomePage();
}
class _HomePage extends State<HomePage>{
  int selectTab=0;
  List<String>titles=[
    "标题1",
    "标题2",
    "标题3",
  ];
  @override
  void initState() {
    super.initState();
  Future.delayed(const Duration(seconds: 2)).then((value){
    showDialog(context: context, builder:(c){
      return LuckyDraw(luckyPrizes:[
        LuckyBean("emmm", Colors.red),
        LuckyBean("emmm", Colors.blue),
        LuckyBean("emmm", Colors.green),
        LuckyBean("emmm", Colors.yellow),
        LuckyBean("emmm", Colors.purple),
        LuckyBean("emmm", Colors.black),
        LuckyBean("emmm", Colors.orangeAccent),
        LuckyBean("emmm", Colors.teal),
        LuckyBean("emmm", Colors.white),
      ],isRandom:false);
    });
  });
  }
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Padding(padding: EdgeInsets.only(top: 10,left: 10,bottom: 10),child: Text("标题标题标题标题标题标题",style: TextStyle(
              fontSize: 16
          ),)),
          Expanded(
            child: Container(
              color: Style.background,
              child: SingleChildScrollView(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children:[
                    SizedBox(
                      height: 500,
                      child: Swiper(itemBuilder:(c,i){
                        return Container(decoration:const BoxDecoration(
                            borderRadius: BorderRadius.vertical(bottom: Radius.circular(10)),
                            image: DecorationImage(image: NetworkImage("https://static-assets-prod.okii.com/xtc-products/z8/pc/scene-section/bg5.jpg"),fit:BoxFit.cover)
                        ));
                      }, itemCount: 4,
                        pagination: SwiperPagination(
                          alignment: Alignment.bottomCenter,
                          margin: const EdgeInsets.only(bottom: 5),
                          builder: DotSwiperPaginationBuilder(
                              space: 5,
                              size: 10,
                              activeSize: 12,
                              color: Colors.white,
                              activeColor: Style.primaryColor),
                        ),),
                    ),
                    const SizedBox(height: 10,),
                    Container(
                      decoration: const BoxDecoration(
                          borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
                          color: Colors.white
                      ),
                      child: Column(
                        children: [
                          Padding(
                            padding: const EdgeInsets.symmetric(vertical: 20),
                            child: Row(mainAxisAlignment: MainAxisAlignment.spaceAround,children: [
                              Column(children: const [
                                Icon(Icons.ac_unit,size: 50,),
                                Text("会员中心"),
                              ],),
                              Column(children: const [
                                Icon(Icons.ac_unit,size: 50,),
                                Text("原装配件"),
                              ],),
                              Column(children: const [
                                Icon(Icons.ac_unit,size: 50,),
                                Text("志趣新品"),
                              ],),
                              Column(children: const [
                                Icon(Icons.ac_unit,size: 50,),
                                Text("拼团"),
                              ],),
                            ],),
                          ),
                          Padding(
                            padding: const EdgeInsets.symmetric(
                                horizontal: 10
                            ),
                            child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,crossAxisAlignment: CrossAxisAlignment.end,children: [
                              Row(children: [
                                Container(
                                  height: 50,
                                  width: 6,
                                  decoration: BoxDecoration(
                                      color: Style.primaryColor,
                                      borderRadius: const BorderRadius.all(Radius.circular(5))
                                  ),
                                ),
                                const SizedBox(width: 10,),
                                Column(crossAxisAlignment: CrossAxisAlignment.start,children: const [
                                  Text("志趣新品",style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 25
                                  ),),
                                  Text("百里挑一的儿童专属好物"),

                                ],
                                )
                              ],),
                              const Text("查看更多>")
                            ],),
                          ),
                          const SizedBox(height: 15,),
                          Padding(
                            padding: const EdgeInsets.symmetric(horizontal: 10),
                            child: Container(
                              decoration: BoxDecoration(
                                  color: Style.background,
                                  borderRadius: const BorderRadius.all(Radius.circular(50))
                              ),
                              height: 50,
                              child: IntrinsicHeight(
                                child: Row(children:List.generate(3, (index){
                                  if(selectTab==index){
                                    return Expanded(
                                      child: Container(
                                        decoration: BoxDecoration(
                                            color: Style.background2,
                                            borderRadius: const BorderRadius.all(Radius.circular(50))
                                        ),
                                        child:Center(
                                          child: Text(titles[index],style: const TextStyle(
                                              fontWeight: FontWeight.bold
                                          )),
                                        ),
                                      ),
                                    );
                                  }else{
                                    return Expanded(
                                      child: InkWell(
                                        onTap:(){
                                          selectTab=index;setState(() {});
                                        },
                                        child: Padding(
                                          padding: const EdgeInsets.symmetric(
                                            vertical: 10,
                                          ),
                                          child: Center(
                                            child: Text(titles[index],style: const TextStyle(
                                                fontWeight: FontWeight.bold
                                            )),
                                          ),
                                        ),
                                      ),
                                    );
                                  }

                                })
                                  ,),
                              ),
                            ),
                          ),
                          const SizedBox(height: 10,),
                          Stack(
                            children: [
                              Padding(
                                padding: const EdgeInsets.only(left: 10,right: 10,bottom: 100),
                                child: Container(
                                  width: double.infinity,
                                  height: 400,
                                  decoration: const BoxDecoration(
                                      image: DecorationImage(image: NetworkImage("https://static-assets-prod.okii.com/xtc-products/z8/pc/scene-section/bg5.jpg"),fit: BoxFit.cover),
                                      borderRadius: BorderRadius.all(Radius.circular(10))
                                  ),
                                ),
                              ),
                              Padding(
                                padding: const EdgeInsets.symmetric(horizontal: 10),
                                child: SizedBox(
                                  width: double.infinity,
                                  height: 620,
                                  child: Align(
                                    alignment: Alignment.bottomLeft,
                                    child: SizedBox(
                                        height: 300,
                                        child: ListView.builder(
                                            scrollDirection: Axis.horizontal,
                                            itemCount: 5,itemBuilder:(c,i){
                                          return InkWell(
                                            onTap:(){
                                              Navigator.push(context, MaterialPageRoute(builder:(c)=>const DetailPage()));
                                            },
                                            child: Padding(
                                              padding: const EdgeInsets.symmetric(horizontal: 10),
                                              child: Container(
                                                decoration: BoxDecoration(
                                                    borderRadius: const BorderRadius.all(Radius.circular(10)),
                                                    color: Colors.white,
                                                    boxShadow: [
                                                      BoxShadow(
                                                          color: Colors.grey.withAlpha(20),
                                                          spreadRadius: 5,
                                                          blurRadius: 5
                                                      )
                                                    ]
                                                ),
                                                child:Column(crossAxisAlignment: CrossAxisAlignment.start,children: [
                                                  Container(
                                                    width: 150,
                                                    height: 200,
                                                    decoration: const BoxDecoration(
                                                        image: DecorationImage(image: NetworkImage("https://static-assets-prod.okii.com/xtc-products/z8/pc/scene-section/bg5.jpg"),fit: BoxFit.cover),
                                                        borderRadius: BorderRadius.vertical(top: Radius.circular(10))
                                                    ),),
                                                  Expanded(
                                                    child: Padding(
                                                      padding: const EdgeInsets.only(left: 10),
                                                      child: Column(
                                                          crossAxisAlignment: CrossAxisAlignment.start,
                                                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                                                          children: [
                                                            const Text("小天才耳机",style:TextStyle(
                                                                fontWeight: FontWeight.bold,
                                                                fontSize: 18
                                                            ),),
                                                            const Text("爱听音乐就选护耳的"),
                                                            Text("¥234",style: TextStyle(
                                                                color: Style.primaryColor,
                                                                fontWeight: FontWeight.bold,
                                                                fontSize: 25
                                                            ),),
                                                          ]),
                                                    ),
                                                  )
                                                ],),
                                              ),
                                            ),
                                          );
                                        })
                                    ),
                                  ),
                                ),
                              )
                            ],
                          ),
                          Container(height: 10,color: Style.background,),
                          Padding(
                            padding: const EdgeInsets.symmetric(
                                horizontal: 10,
                                vertical: 10
                            ),
                            child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween,crossAxisAlignment: CrossAxisAlignment.end,children: [
                              Row(children: [
                                Container(
                                  height: 50,
                                  width: 6,
                                  decoration: BoxDecoration(
                                      color: Style.primaryColor,
                                      borderRadius: const BorderRadius.all(Radius.circular(5))
                                  ),
                                ),
                                const SizedBox(width: 10,),
                                Column(crossAxisAlignment: CrossAxisAlignment.start,children: const [
                                  Text("会员俱乐部",style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 25
                                  ),),
                                  Text("小天才会员专属特权"),
                                ],
                                )
                              ],),
                              const Text("领108元新人礼权>")
                            ],),
                          ),
                          const Padding(padding:EdgeInsets.symmetric(vertical: 20),child: Text("下面页面都是重复页面，先不写了")),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}